package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.entity.Statute;
import cn.swh.guguanjia.service.StatuteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/mapper/statute")
public class StatuteController {

    /**
     * @Description
     * @Params
     * @return
     **/


    @Autowired
    StatuteService service;

    @RequestMapping("")
    public ModelAndView index() {
        return new ModelAndView("/statute/index.html");
    }



    @RequestMapping("index")
    public Result listAll() {
        return new Result(service.selectAll());
    }


    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, @RequestParam Map<String, Object> map) {
        return new Result(service.selectPage(pageNum, pageSize, map));
    }

    @RequestMapping({"/toUpdate", "/update.html"})
    public ModelAndView toUpdate() {
        return new ModelAndView("/statute/update.html");
    }

    @RequestMapping(value = "doUpdate", method = RequestMethod.POST)
    public Result doUpdate(@RequestBody Statute statute) {
        statute.setUpdateDate(new Date());
        return new Result(service.updateByPrimaryKeySelective(statute));
    }

    @RequestMapping(value = "insert",method = RequestMethod.POST)
    public Result insert(@RequestBody Statute statute){
        statute.setCreateDate(new Date());
        statute.setUpdateDate(new Date());
        statute.setDelFlag("0");
        return new Result(service.insertSelective(statute));

    }


}
